<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="../../js/base.js" data-path="../../"></script>
    <link rel="shortcut icon" href="../../static/img/common/logo.png">
    <title></title>
    <style>
        /* 默认隐藏盒子 */
        #main {
            display: none;
        }
    </style>

</head>

<body>
    <div id="main">
        <div class="register">
            <div class="register_form">
                <div-div1></div-div1>
                <div class="header title_linear1">
                    <h2>注册新用户</h2>
                </div>
                <div class="form">
                    <div class="group-form">
                        <div class="group-label">用户名</div>
                        <input id="userName" placeholder="请输入用户名" required type="text">
                    </div>
                    <div class="group-form">
                        <div class="group-label">密码</div>
                        <input id="password" type="password" placeholder="请输入密码" required>
                    </div>
                    <div class="group-form">
                        <div class="group-label">确认密码</div>
                        <input id="confirmPassword" type="password" placeholder="请确认密码" required>
                    </div>
                    <div class="group-form">
                        <div class="group-label"></div>
                        <button type="button" class="btn" onclick="window.history.back()">返回登录</button>
                        <button type="button" class=" btn bg-blue" onclick="register()">注册</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bgComponent">
        <honey-pattern></honey-pattern>
    </div>
</body>
<script>
    // 页面加载完成回调函数
    function onReady() {
        console.log("onReady");
        checkLoginStatus();
    }
    // 注册
    function register() {
        let name = getEleVal("userName").value;
        let password = getEleVal("password").value;
        let confirmPassword = getEleVal("confirmPassword").value;
        if (name && password && confirmPassword) {
            if (password == confirmPassword) {
                let user = {
                    id: getUUID(),
                    name,
                    password,
                    times:getCurrentDateTime()
                }
                let accountLists = getStorage("accountLists") || globalDatas.datas.accountLists;
                // 对已存在的用户列表进行查询
                if (accountLists.filter(item => {
                    return item.name == user.name;
                })[0]) {
                    ice.pop({
                        icon: "fail",
                        content: `用户名：${user.name} 已存在,请重新命名~`
                    })
                    return;
                } else {
                    user.password = aesEncrypt(user.password); // 加密密码
                    accountLists.push(user);
                    globalDatas.datas.accountLists = accountLists;
                    setStorage("accountLists", accountLists);
                    ice.pop({
                        icon: "success",
                        content: `注册用户：${user.name} 成功～`
                    })
                }

            } else {
                ice.pop({
                    icon: "warning",
                    content: "2次输入密码不一致,请重新检查～"
                })
            }
        } else {
            ice.pop({
                icon: "warning",
                content: "请输入用户名、密码、确认密码～"
            })
        }
    }
</script>

</html>